<?php if (isset($this->options)): ?> 
    <?php
    $this->headScript()->appendFile($this->baseUrl() . '/application/modules/Poll/externals/scripts/core.js');
    $poll = $this->item; 
    $paginator = $this->options;    
    if ($paginator instanceof Zend_Paginator) {        
        $maxItemShow = Engine_Api::_()->getApi('Settings', 'Core')->getSetting('poll.items.displayed', 3);
        $paginator->setItemCountPerPage($maxItemShow);    
    } 
    $viewer = $this->viewer ? $this->viewer : Engine_Api::_()->user()->getViewer();
    $voted = $poll->getUserVoted($viewer);
    $moreUrl = $this->url(array('controller' => 'poll', 'action' => 'show-all-option'), 'poll_general', true);
    $this->addHelperPath(APPLICATION_PATH . DS . 'application' . DS . 'libraries' . DS . 'Zend' . DS . 'View' . DS . 'Helper', 'Zend_View_Helper_');    
    $this->addHelperPath(APPLICATION_PATH . DS . 'application' . DS . 'libraries' . DS . 'Engine' . DS . 'View' . DS . 'Helper', 'Engine_View_Helper_');
    $this->addHelperPath(APPLICATION_PATH . DS . 'application' . DS . 'modules' . DS . 'Core' . DS . 'View' . DS . 'Helper', 'Core_View_Helper_');    
    $this->addHelperPath(APPLICATION_PATH . DS . 'application' . DS . 'modules' . DS . 'Poll' . DS . 'View' . DS . 'Helper', 'Poll_View_Helper_');    
    $rand = mt_rand();
    ?> 
    <ul class="poll_options" id="poll_feed_<?php echo $poll->getIdentity();?>_<?php echo $rand;?>"<?php echo $this->isFeed ? 'isFeed="1"' : '';?>>
    <?php foreach ($paginator as $option): ?>
        <li>
            <div class="options_checkbox" onclick="Poll.vote($(this), <?php echo $poll->getIdentity();?>, <?php echo $option->getIdentity();?>, <?php echo $this->show_all ? 1 : 0;?>, <?php echo $viewer->getIdentity() ? 1 : 0;?>);">
                <input type="checkbox" value="<?php echo $option->getIdentity();?>" <?php if (is_array($voted) && in_array($option->getIdentity(), $voted)): ?>checked="checked"<?php endif;?>/>
            </div>
            <div class="options_content <?php if ($option->votes):?>voted<?php endif;?>" onclick="Poll.vote($(this), <?php echo $poll->getIdentity();?>, <?php echo $option->getIdentity();?>, <?php echo $this->show_all ? 1 : 0;?>, <?php echo $viewer->getIdentity() ? 1 : 0;?>);">
                <?php
                $percent = $poll->total_votes ? round($option->votes / $poll->total_votes, 2) * 100 : 0;                    
                ?>
                <?php if ($option->votes && $percent):?><div class="options_content_shade" style="width: <?php echo $percent;?>%;"></div><?php endif; ?>
                <div class="options_content_label"><?php echo $option->getTitle();?></div>
                <div class="options_content_votes"><span class="pad-top"></span><?php echo $this->translate(array("%s vote", "%s votes", $option->votes),
        $this->locale()->toNumber($option->votes));?></div>
            </div>
            <div class="options_voter">
            <?php $maxVotersShow = 6; $votes = $option->getVotes($maxVotersShow, $viewer); $userApi = Engine_Api::_()->user(); $isVoted = false;?>
            <?php foreach($votes as $item):?>
                <?php 
                $user = $userApi->getUser($item->user_id);
                if ($user->getIdentity() == $viewer->getIdentity()) $isVoted = true;
                echo $this->htmlLink($user->getHref(), $this->uPhoto($user, 'thumb.icon'), array('title' => $user->getTitle())); ?>
            <?php endforeach; ?>
            <?php if ($option->votes > $maxVotersShow): ?>
                <?php
                $remains = $option->votes - $maxVotersShow;                
                $otherVotesTxt = $isVoted ? $this->translate('%s other people', $remains) : $this->translate('%s people', $remains);
                ?>
                <a href="<?php echo $viewer->getIdentity() ? $this->url(array('controller' => 'poll', 'action' => 'voters', 'option' => $option->getIdentity()), 'poll_general', true) : 'javascript:void(0)';?>" class="more_voters<?php echo $viewer->getIdentity() ? ' smoothbox' : '';?>" title="<?php echo $otherVotesTxt . ' - ' . $this->translate('People who voted for this option');?>">                
                <i class="tipWrap" onmouseover="$(this).getNext().setStyle('display', 'inline-block');" onmouseout="$(this).getNext().setStyle('display', 'none');">...</i>
                <span class="tipWrapTotal">
                    <span class="tipWrapTotalText"><?php echo $otherVotesTxt;?></span>
                </span>
                </a>
            <?php endif; ?>
            </div> 
        </li>                                    
    <?php endforeach; ?> 
    
    <?php if ($paginator instanceof Zend_Paginator && $paginator->getTotalItemCount() > $maxItemShow): ?>
    <li>
        <div class="options_checkbox"><input type="checkbox" style="visibility: hidden;" /></div>
        <div class="options_more">
        <a href="<?php echo $this->url(array('controller' => 'poll', 'action' => 'show-all-options', 'poll' => $poll->getIdentity()), 'poll_general', true);?>" class="smoothbox" title="<?php echo $poll->getTitle();?>"><?php echo ($paginator->getTotalItemCount() - $maxItemShow);?> <?php echo $this->translate('more');?></a>
        </div>
    </li>
    <?php else :?>
        <?php if ($viewer->getIdentity() && ($poll->allow_add_option || $poll->user_id == $viewer->getIdentity())):?>
        <li>
            <div class="input_div">
                <input type="text" size="20" value="<?php echo $this->translate('Add an option...');?>" onfocus="clearText(this);" onblur="clearText(this)"/>
                <a href="javascript:void(0)" class="fb_add fb_btn" onclick="Poll.addOpt($(this), $(this).getParent('div').getParent('li'), <?php echo $poll->getIdentity();?>, <?php echo $this->show_all ? 1 : 0;?>);"><?php echo $this->translate('Add');?></a>
            </div>
        </li>
        <?php endif;?>
    <?php endif; ?>
    </ul>
    
    <?php if ($viewer->getIdentity()):?> 
        <?php $isFollowed = $poll->isFollowed($viewer) ? 1 : 0; $isSelf = ($poll->user_id == $viewer->getIdentity()) ? 1 : 0;?>
        <?php if ($this->isFeed):?> 
        <script type="text/javascript">
        <?php $params = array('votes' => $poll->total_votes, 'title' => $poll->getTitle());?>
        if (!window.isLoaded) window.addEvent('domready', function(){Poll.attachFeeds(<?php echo $poll->getIdentity();?>, <?php echo $rand;?>, <?php echo $isSelf;?>, <?php echo $isFollowed;?>, <?php echo Zend_Json::encode($params);?>);});
        else setTimeout(function(){Poll.attachFeeds(<?php echo $poll->getIdentity();?>, <?php echo $rand;?>, <?php echo $isSelf;?>, <?php echo $isFollowed;?>, <?php echo Zend_Json::encode($params);?>);}, 200);
        </script>
        <?php else: ?>             
            <?php if (!$this->noInfo):?>    
            <div class="poll_other_info">
                <ul>
                    <li><?php echo $this->timestamp($poll->creation_date);?></li>
                    <li> · <a class="a_poll_more" href="javascript:Poll.show(<?php echo $poll->getIdentity();?>, '<?php echo $poll->getTitle();?>')"><i class="fb_check fb_icons3"></i><span><?php echo $poll->total_votes;?></span></a></li>
                    <?php if (!$isSelf): ?>
                    <li> · <a title="<?php echo $isFollowed ? $this->translate('Unfollow') : $this->translate('Follow');?>" href="javascript:void(0);" onclick="Poll.follow($(this), <?php echo $poll->getIdentity();?>);"><?php echo $isFollowed ? $this->translate('Unfollow') : $this->translate('Follow');?></a></li>
                    <?php endif;?>
                    <li> · <a class="smoothbox" title="Ask Friends" href="<?php echo $this->url(array('controller' => 'poll', 'action' => 'ask-friends', 'poll' => $poll->getIdentity()), 'poll_general', true);?>"><?php echo $this->translate('Ask Friends');?></a></li>
                </ul> 
            </div>
            <?php endif; ?>
        <?php endif;?>    
    <?php endif; ?>
<?php endif; ?>